import ky from 'ky';

import { User } from '../model/user';

export const login = async (username: string, password: string): Promise<User> => {
  return await ky.post('/api/user/login', { json: { username, password } }).json();
};

export const register = async (username: string, password: string): Promise<User> => {
  return await ky.post('/api/user/register', { json: { username, password } }).json();
};

export const logout = async (): Promise<{ok:boolean}> => {
  return await ky.post('/api/user/logout').json();
};

export const load = async (): Promise<User> => {
  return await ky.get('/api/user/current').json();
};
